<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <meta name="google-site-verification" content="k9iQUbEI9rWq3xYeh63ATztKdkthC4dNRHV_25maJ3Q" />
  <title>Mac下安装LNMP(Nginx+PHP5.6)环境 | Taylor&#39;s Learning Diary</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="安装Homebrew从零开始安装Mac下LNMP环境的过程  确保系统已经安装xcode，然后使用一行命令安装依赖管理工具Homebrew  1ruby -e &quot;$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)&quot; 之后就可以使用1brew install FORMULA 来安装所需要的依赖">
<meta name="keywords" content="Mac">
<meta property="og:type" content="article">
<meta property="og:title" content="Mac下安装LNMP(Nginx+PHP5.6)环境">
<meta property="og:url" content="https://upeng.github.io/blog/2016/08/28/mac-lnmp/index.html">
<meta property="og:site_name" content="Taylor&#39;s Learning Diary">
<meta property="og:description" content="安装Homebrew从零开始安装Mac下LNMP环境的过程  确保系统已经安装xcode，然后使用一行命令安装依赖管理工具Homebrew  1ruby -e &quot;$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)&quot; 之后就可以使用1brew install FORMULA 来安装所需要的依赖">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2017-09-14T16:44:21.976Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Mac下安装LNMP(Nginx+PHP5.6)环境">
<meta name="twitter:description" content="安装Homebrew从零开始安装Mac下LNMP环境的过程  确保系统已经安装xcode，然后使用一行命令安装依赖管理工具Homebrew  1ruby -e &quot;$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)&quot; 之后就可以使用1brew install FORMULA 来安装所需要的依赖">
  
    <link rel="alternate" href="/atom.xml" title="Taylor&#39;s Learning Diary" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link rel="stylesheet" href="/blog/css/style.css">
  

</head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/blog/" id="logo">Taylor&#39;s Learning Diary</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/blog/">Home</a>
        
          <a class="main-nav-link" href="/blog/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="搜索"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="https://upeng.github.io/blog"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-mac-lnmp" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/blog/2016/08/28/mac-lnmp/" class="article-date">
  <time datetime="2016-08-28T14:28:49.000Z" itemprop="datePublished">2016-08-28</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/blog/categories/其他/">其他</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      Mac下安装LNMP(Nginx+PHP5.6)环境
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="安装Homebrew"><a href="#安装Homebrew" class="headerlink" title="安装Homebrew"></a>安装Homebrew</h2><p>从零开始安装Mac下LNMP环境的过程</p>
<blockquote>
<p>确保系统已经安装xcode，然后使用一行命令安装依赖管理工具Homebrew</p>
</blockquote>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/<span class="keyword">install</span>/<span class="keyword">master</span>/<span class="keyword">install</span>)<span class="string">"</span></div></pre></td></tr></table></figure>
<p>之后就可以使用<br><figure class="highlight mipsasm"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">brew </span><span class="keyword">install </span>FORMULA</div></pre></td></tr></table></figure></p>
<p>来安装所需要的依赖了.更详细的信息参考Homebrew的[官方Cookbook][1]</p>
<p>因此使用Homebrew常见的流程是：</p>
<ol>
<li>增加一个程序源（新增一个水龙头） brew tap homebrew/php</li>
<li>更新程序源 brew update</li>
<li>安装程序包（按照配方酿酒） brew install git</li>
<li>查看配置 brew config 可以看到程序包默认安装在/usr/local/Cellar下 （酒桶放在地窖内）<a id="more"></a>
<h2 id="安装PHP5-6（FPM方式）"><a href="#安装PHP5-6（FPM方式）" class="headerlink" title="安装PHP5.6（FPM方式）"></a>安装PHP5.6（FPM方式）</h2>首先加入Homebrew官方的几个软件源<figure class="highlight armasm"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">brew </span>tap homebrew/dupes</div><div class="line"><span class="keyword">brew </span>tap homebrew/versions</div><div class="line"><span class="keyword">brew </span>tap homebrew/php</div></pre></td></tr></table></figure>
</li>
</ol>
<p>PHP如果采用默认配置安装，会编译mod_php模块并只运行在Apache环境下，为了使用Nginx，这里需要编译php-fpm并且禁用apache，主要通过参数<code>--without-fpm --without-apache</code>来实现。完整的安装指令为<br><figure class="highlight haml"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line">brew install php56 \</div><div class="line">-<span class="ruby">-without-snmp \</span></div><div class="line"><span class="ruby">--without-apache \</span></div><div class="line"><span class="ruby">--with-debug \</span></div><div class="line"><span class="ruby">--with-fpm \</span></div><div class="line"><span class="ruby">--with-intl \</span></div><div class="line"><span class="ruby">--with-homebrew-curl \</span></div><div class="line"><span class="ruby">--with-homebrew-libxslt \</span></div><div class="line"><span class="ruby">--with-homebrew-openssl \</span></div><div class="line"><span class="ruby">--with-imap \</span></div><div class="line"><span class="ruby">--with-mysql \</span></div><div class="line"><span class="ruby">--with-tidy</span></div></pre></td></tr></table></figure></p>
<p>由于OSX已经自带了PHP5.5环境，因此需要修改系统路径，优先运行brew安装的版本，在<code>~/.bashrc</code>里加入：<br><figure class="highlight routeros"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="builtin-name">export</span> <span class="attribute">PATH</span>=<span class="string">"/usr/local/bin:/usr/local/sbin:<span class="variable">$PATH</span>"</span></div></pre></td></tr></table></figure></p>
<blockquote>
<p>这时运行 php -v查看版本是否是5.6<br>运行php -m 查看PHP安装都扩展列表</p>
</blockquote>
<p>如果要安装新的php扩展，可以直接安装而不用每次重新编译php，所有的扩展可以通过<br><figure class="highlight armasm"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">brew </span>search php56</div></pre></td></tr></table></figure></p>
<p>看到，下面是我自己所需要的扩展，可以支持Phalcon框架：<br><figure class="highlight smali"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">brew install php56-gearman php56-msgpack php56-memcache php56-memcached php56-mongo  php56-phalcon php56-redis php56-xdebug</div></pre></td></tr></table></figure></p>
<h3 id="PHP-FPM的加载与启动"><a href="#PHP-FPM的加载与启动" class="headerlink" title="PHP-FPM的加载与启动"></a>PHP-FPM的加载与启动</h3><p>php-fpm.conf  php.ini<br><figure class="highlight awk"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="regexp">/usr/</span>local<span class="regexp">/etc/</span>php<span class="regexp">/5.6</span></div></pre></td></tr></table></figure></p>
<p>php-fpm进程<br><figure class="highlight applescript"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">/usr/<span class="keyword">local</span>/sbin</div></pre></td></tr></table></figure></p>
<p><strong>安装完毕后可以通过以下指令启动和停止php-fpm</strong><br><figure class="highlight jboss-cli"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><span class="string">./php-fpm</span> -D    <span class="string">//</span>进入sbin目录</div><div class="line"></div><div class="line">killall php-fpm</div></pre></td></tr></table></figure></p>
<p>同时可以将php-fpm加入开机启动<br><figure class="highlight jboss-cli"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">ln -sfv <span class="string">/usr/local/opt/php56/</span>*<span class="string">.plist</span> ~<span class="string">/Library/LaunchAgents</span></div><div class="line"></div><div class="line">launchctl load ~<span class="string">/Library/LaunchAgents/homebrew.mxcl.php56.plist</span></div></pre></td></tr></table></figure></p>
<h3 id="查看php-fpm进程"><a href="#查看php-fpm进程" class="headerlink" title="查看php-fpm进程"></a>查看php-fpm进程</h3><p>查看9000端口<br><code>lsof -i:9000</code><br>或者<br><code>ps -ef | grep php-fpm</code></p>
<h2 id="安装Nginx"><a href="#安装Nginx" class="headerlink" title="安装Nginx"></a>安装Nginx</h2><figure class="highlight mipsasm"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">brew </span><span class="keyword">install </span>nginx</div></pre></td></tr></table></figure>
<p>安装完毕后可以通过<br><figure class="highlight cos"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">nginx</div><div class="line">nginx -<span class="keyword">s</span> <span class="keyword">quit</span></div></pre></td></tr></table></figure></p>
<p>启动和关闭，同时也支持重载配置文件等操作<br><figure class="highlight coq"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">nginx -s reload|<span class="type">reopen</span>|<span class="type">stop</span>|<span class="type">quit</span></div></pre></td></tr></table></figure></p>
<p>nginx安装后默认监听8080端口，可以访问<a href="http://localhost:8080" target="_blank" rel="external">http://localhost:8080</a> 查看状态。如果要想监听80端口需要root权限，运行</p>
<figure class="highlight groovy"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">sudo chown <span class="string">root:</span>wheel <span class="regexp">/usr/</span>local<span class="regexp">/Cellar/</span>nginx<span class="regexp">/1.6.2/</span>bin/nginx</div><div class="line">sudo chmod u+s <span class="regexp">/usr/</span>local<span class="regexp">/Cellar/</span>nginx<span class="regexp">/1.6.2/</span>bin/nginx</div></pre></td></tr></table></figure>
<blockquote>
<p>我是直接在nginx配置中改成80端口，然后重启生效<br>并使用root权限启动</p>
</blockquote>
<figure class="highlight ebnf"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="attribute">sudo nginx</span></div></pre></td></tr></table></figure>
<p>开机启动<br><figure class="highlight jboss-cli"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">ln -sfv <span class="string">/usr/local/opt/nginx/</span>*<span class="string">.plist</span> ~<span class="string">/Library/LaunchAgents</span></div><div class="line"></div><div class="line">launchctl load ~<span class="string">/Library/LaunchAgents/homebrew.mxcl.nginx.plist</span></div></pre></td></tr></table></figure></p>
<h2 id="Nginx-PHP-FPM配置"><a href="#Nginx-PHP-FPM配置" class="headerlink" title="Nginx + PHP-FPM配置"></a>Nginx + PHP-FPM配置</h2><p>好文：<a href="http://www.nginx.cn/nginx-how-to" target="_blank" rel="external">http://www.nginx.cn/nginx-how-to</a></p>
<p>Nginx一般都会运行多个域名（虚拟主机）</p>
<blockquote>
<p>按Ubuntu的文件夹结构来存放Nginx的配置文件</p>
</blockquote>
<figure class="highlight stata"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">mkdir</span> -p /usr/<span class="keyword">local</span>/<span class="keyword">var</span>/logs/nginx</div><div class="line"><span class="keyword">mkdir</span> -p /usr/<span class="keyword">local</span>/etc/nginx/sites-available</div><div class="line"><span class="keyword">mkdir</span> -p /usr/<span class="keyword">local</span>/etc/nginx/sites-enabled</div><div class="line"><span class="keyword">mkdir</span> -p /usr/<span class="keyword">local</span>/etc/nginx/<span class="keyword">conf</span>.<span class="built_in">d</span></div><div class="line"><span class="keyword">mkdir</span> -p /usr/<span class="keyword">local</span>/etc/nginx/ssl</div></pre></td></tr></table></figure>
<blockquote>
<p>联想到work中，vhost和fpm.d目录，新增域名与目录时，只需要增加两个配置文件；前提时php-fpm.conf和nginx.conf主配置文件中都有</p>
</blockquote>
<figure class="highlight nginx"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line"><span class="attribute">include</span> vhost/<span class="regexp">*.conf</span></div><div class="line">include fpm.d/<span class="regexp">*.conf</span></div></pre></td></tr></table></figure>
<p><strong>上述都conf.d等同于fpm.d，sites-enabled等同于vhost</strong></p>
<h3 id="编辑Nginx全局配置"><a href="#编辑Nginx全局配置" class="headerlink" title="编辑Nginx全局配置"></a>编辑Nginx全局配置</h3><figure class="highlight awk"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">vim <span class="regexp">/usr/</span>local<span class="regexp">/etc/</span>nginx<span class="regexp">/nginx.conf</span></div></pre></td></tr></table></figure>
<figure class="highlight nginx"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div></pre></td><td class="code"><pre><div class="line"><span class="attribute">worker_processes</span>  <span class="number">1</span>;</div><div class="line"><span class="attribute">error_log</span>   /usr/local/var/logs/nginx/error.log <span class="literal">debug</span>;</div><div class="line"><span class="attribute">pid</span>        /usr/local/var/run/nginx.pid;</div><div class="line"></div><div class="line"><span class="section">events</span> &#123;</div><div class="line">    <span class="attribute">worker_connections</span>  <span class="number">256</span>;</div><div class="line">&#125;</div><div class="line"></div><div class="line"></div><div class="line"><span class="section">http</span> &#123;</div><div class="line">    <span class="attribute">include</span>       mime.types;</div><div class="line">    <span class="attribute">default_type</span>  application/octet-stream;</div><div class="line"></div><div class="line">    <span class="attribute">log_format</span> main <span class="string">'<span class="variable">$remote_addr</span> - <span class="variable">$remote_user</span> [<span class="variable">$time_local</span>] '</span></div><div class="line">        <span class="string">'"<span class="variable">$request</span>" <span class="variable">$status</span> <span class="variable">$body_bytes_sent</span> '</span></div><div class="line">        <span class="string">'"<span class="variable">$http_referer</span>" "<span class="variable">$http_user_agent</span>" '</span></div><div class="line">        <span class="string">'"<span class="variable">$http_x_forwarded_for</span>" <span class="variable">$host</span> <span class="variable">$request_time</span> <span class="variable">$upstream_response_time</span> <span class="variable">$scheme</span> '</span></div><div class="line">        <span class="string">'<span class="variable">$cookie_evalogin</span>'</span>;</div><div class="line"></div><div class="line">    <span class="attribute">access_log</span>  /usr/local/var/logs/access.log  main;</div><div class="line"></div><div class="line">    <span class="attribute">sendfile</span>        <span class="literal">on</span>;</div><div class="line">    <span class="attribute">keepalive_timeout</span>  <span class="number">65</span>;</div><div class="line">    <span class="attribute">port_in_redirect</span> <span class="literal">off</span>;</div><div class="line"></div><div class="line">    <span class="attribute">include</span> /usr/local/etc/nginx/sites-enabled/*;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>这样一来首先可以把一些可复用配置独立出来放在<code>/usr/local/etc/nginx/conf.d</code>下，比如fastcgi的设置就可以独立出来<br><figure class="highlight awk"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">vim <span class="regexp">/usr/</span>local<span class="regexp">/etc/</span>nginx<span class="regexp">/conf.d/</span>php-fpm</div></pre></td></tr></table></figure></p>
<p>内容为<br><figure class="highlight nginx"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line"><span class="attribute">location</span> <span class="regexp">~ \.php$</span> &#123;</div><div class="line">    <span class="attribute">try_files</span>                   <span class="variable">$uri</span> = <span class="number">404</span>;</div><div class="line">    <span class="attribute">fastcgi_pass</span>                <span class="number">127.0.0.1:9000</span>;</div><div class="line">    <span class="attribute">fastcgi_index</span>               index.php;</div><div class="line">    <span class="attribute">fastcgi_intercept_errors</span>    <span class="literal">on</span>;</div><div class="line">    <span class="attribute">include</span> /usr/local/etc/nginx/fastcgi.conf;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<p>然后<code>/usr/local/etc/nginx/sites-enabled</code>目录下可以一个文件对应一个域名的配置，比如web服务器目录是<code>/opt/htdocs</code><br><figure class="highlight gradle"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">vim <span class="regexp">/usr/</span>local<span class="regexp">/etc/</span>nginx<span class="regexp">/sites-enabled/</span><span class="keyword">default</span></div></pre></td></tr></table></figure></p>
<figure class="highlight nginx"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line"><span class="section">server</span> &#123;</div><div class="line">    <span class="attribute">listen</span>       <span class="number">80</span>;</div><div class="line">    <span class="attribute">server_name</span>  localhost;</div><div class="line">    <span class="attribute">root</span>         /opt/htdocs/;</div><div class="line"></div><div class="line">    <span class="attribute">location</span> / &#123;</div><div class="line">        <span class="attribute">index</span>  index.html index.htm index.php;</div><div class="line">        <span class="attribute">include</span>     /usr/local/etc/nginx/conf.d/php-fpm;</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>此时启动了php-fpm并且启动了Nginx后，就可以通过<a href="http://localhost来运行php程序了" target="_blank" rel="external">http://localhost来运行php程序了</a></p>
<h2 id="安装MySQL"><a href="#安装MySQL" class="headerlink" title="安装MySQL"></a>安装MySQL</h2><figure class="highlight mipsasm"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">brew </span><span class="keyword">install </span>mysql</div></pre></td></tr></table></figure>
<p>可以通过<br><figure class="highlight stylus"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">mysql<span class="selector-class">.server</span> start</div><div class="line">mysql<span class="selector-class">.server</span> stop</div></pre></td></tr></table></figure></p>
<p>来启动／停止，启动后默认应为空密码，可以通过mysqladmin设置一个密码<br><figure class="highlight nginx"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="attribute">mysqladmin</span> -uroot password <span class="string">"mypassword"</span></div></pre></td></tr></table></figure></p>
<p>但是在操作的时候出现了空密码无法登入的情况，最终只能通过mysqld_safe来设置<br><figure class="highlight n1ql"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">sudo mysqld_safe --skip-grant-tables</div><div class="line">mysql -u root</div><div class="line">mysql&gt; <span class="keyword">UPDATE</span> mysql.<span class="keyword">user</span> <span class="keyword">SET</span> <span class="keyword">Password</span>=<span class="keyword">PASSWORD</span>(<span class="string">'mypassword'</span>) <span class="keyword">WHERE</span> <span class="keyword">User</span>=<span class="string">'root'</span>;</div><div class="line">mysql&gt; FLUSH PRIVILEGES;</div></pre></td></tr></table></figure></p>
<p><strong>依旧报错</strong></p>
<blockquote>
<p><strong>坑1</strong>：一直出现mysql.sock错误，<code>mysql -uroot -p</code>;<br><strong>填坑1</strong>：<code>mysql -h 127.0.0.1 -u root -p</code>  why?</p>
<p><strong>坑2</strong>：设置密码报错：<code>Password</code>字段不存在<br><strong>填坑2</strong>：mysql5.7已将<code>Password</code>字段去掉，改成<code>authentication_string</code>；所以正确都姿势如下：<br><figure class="highlight n1ql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">update</span> mysql.<span class="keyword">user</span> <span class="keyword">set</span> authentication_string=<span class="keyword">password</span>(<span class="string">'123qwe'</span>) <span class="keyword">where</span> <span class="keyword">user</span>=<span class="string">'root</span></div></pre></td></tr></table></figure></p>
<p>老版本mysql没变</p>
</blockquote>
<p>最后将MySQL加入开机启动<br><figure class="highlight awk"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">cp <span class="regexp">/usr/</span>local<span class="regexp">/Cellar/my</span>sql<span class="regexp">/5.6.22/</span>homebrew.mxcl.mysql.plist ~<span class="regexp">/Library/</span>LaunchAgents<span class="regexp">/</span></div></pre></td></tr></table></figure></p>
<h2 id="查看服务列表"><a href="#查看服务列表" class="headerlink" title="查看服务列表"></a>查看服务列表</h2><figure class="highlight applescript"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">brew services <span class="built_in">list</span></div></pre></td></tr></table></figure>
<figure class="highlight stylus"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">Name  Status  User    Plist</div><div class="line">mysql started root    /Library/LaunchDaemons/homebrew<span class="selector-class">.mxcl</span><span class="selector-class">.mysql</span><span class="selector-class">.plist</span></div><div class="line">nginx started yupeng6 /Users/yupeng6/Library/LaunchAgents/homebrew<span class="selector-class">.mxcl</span><span class="selector-class">.nginx</span><span class="selector-class">.plist</span></div><div class="line">php56 started yupeng6 /Users/yupeng6/Library/LaunchAgents/homebrew<span class="selector-class">.mxcl</span><span class="selector-class">.php56</span><span class="selector-class">.plist</span></div></pre></td></tr></table></figure>
<p>安装redis和memcache过程省略，详见下面博文，本文也是参考此<br><a href="http://avnpc.com/pages/install-lnmp-on-osx" target="_blank" rel="external">http://avnpc.com/pages/install-lnmp-on-osx</a></p>

      
    </div>
    <footer class="article-footer">
      <a data-url="https://upeng.github.io/blog/2016/08/28/mac-lnmp/" data-id="cj8x7817j0017gwp4t376hwgw" class="article-share-link">Share</a>
      
        <a href="https://upeng.github.io/blog/2016/08/28/mac-lnmp/#disqus_thread" class="article-comment-link">留言</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog/tags/Mac/">Mac</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/blog/2016/09/11/vim/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          vim学习笔记
        
      </div>
    </a>
  
  
    <a href="/blog/2016/08/28/mac-primary/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">首次折腾Mac</div>
    </a>
  
</nav>

  
</article>


<section id="comments">
  <div id="disqus_thread">
    <noscript>Please enable JavaScript to view the <a href="//disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
  </div>
</section>
</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">分类</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/blog/categories/Linux/">Linux</a><span class="category-list-count">8</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/MySQL/">MySQL</a><span class="category-list-count">6</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/PHP/">PHP</a><span class="category-list-count">15</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/Thinking/">Thinking</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/其他/">其他</a><span class="category-list-count">8</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/前端/">前端</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/数据库范式/">数据库范式</a><span class="category-list-count">1</span></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">标签云</h3>
    <div class="widget tagcloud">
      <a href="/blog/tags/CI/" style="font-size: 10px;">CI</a> <a href="/blog/tags/JQuery/" style="font-size: 10px;">JQuery</a> <a href="/blog/tags/Mac/" style="font-size: 13.33px;">Mac</a> <a href="/blog/tags/MySQL/" style="font-size: 10px;">MySQL</a> <a href="/blog/tags/awk/" style="font-size: 10px;">awk</a> <a href="/blog/tags/bash/" style="font-size: 10px;">bash</a> <a href="/blog/tags/composer/" style="font-size: 10px;">composer</a> <a href="/blog/tags/eloquent/" style="font-size: 10px;">eloquent</a> <a href="/blog/tags/hexo/" style="font-size: 10px;">hexo</a> <a href="/blog/tags/idempotence/" style="font-size: 10px;">idempotence</a> <a href="/blog/tags/item/" style="font-size: 10px;">item</a> <a href="/blog/tags/laravel/" style="font-size: 20px;">laravel</a> <a href="/blog/tags/linux/" style="font-size: 16.67px;">linux</a> <a href="/blog/tags/mac/" style="font-size: 10px;">mac</a> <a href="/blog/tags/memcacheq/" style="font-size: 10px;">memcacheq</a> <a href="/blog/tags/mysql/" style="font-size: 16.67px;">mysql</a> <a href="/blog/tags/nc/" style="font-size: 10px;">nc</a> <a href="/blog/tags/packageist/" style="font-size: 10px;">packageist</a> <a href="/blog/tags/php/" style="font-size: 13.33px;">php</a> <a href="/blog/tags/sed/" style="font-size: 10px;">sed</a> <a href="/blog/tags/shell/" style="font-size: 10px;">shell</a> <a href="/blog/tags/static/" style="font-size: 10px;">static</a> <a href="/blog/tags/thinking/" style="font-size: 13.33px;">thinking</a> <a href="/blog/tags/tmux/" style="font-size: 10px;">tmux</a> <a href="/blog/tags/vagrant/" style="font-size: 10px;">vagrant</a> <a href="/blog/tags/validator/" style="font-size: 10px;">validator</a> <a href="/blog/tags/vim/" style="font-size: 10px;">vim</a> <a href="/blog/tags/vuejs/" style="font-size: 10px;">vuejs</a> <a href="/blog/tags/zephir/" style="font-size: 10px;">zephir</a> <a href="/blog/tags/zsh/" style="font-size: 10px;">zsh</a> <a href="/blog/tags/设计模式/" style="font-size: 13.33px;">设计模式</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">归档</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2017/10/">十月 2017</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2017/09/">九月 2017</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2016/12/">十二月 2016</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2016/11/">十一月 2016</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2016/10/">十月 2016</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2016/09/">九月 2016</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2016/08/">八月 2016</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2016/07/">七月 2016</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2016/06/">六月 2016</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2016/05/">五月 2016</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2016/04/">四月 2016</a><span class="archive-list-count">7</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2016/02/">二月 2016</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2016/01/">一月 2016</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2015/10/">十月 2015</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2015/08/">八月 2015</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2015/07/">七月 2015</a><span class="archive-list-count">1</span></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">最新文章</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/blog/2017/10/18/laravel-validator/">Laravel Validator自定义参数验证规则</a>
          </li>
        
          <li>
            <a href="/blog/2017/09/28/linux-sed/">linux常用命令之sed</a>
          </li>
        
          <li>
            <a href="/blog/2017/09/27/shell-script-learning/">shell脚本由点到面学习总结</a>
          </li>
        
          <li>
            <a href="/blog/2017/09/14/laravel-eloquent-index/">Eloquent ORM多个and和or条件查询</a>
          </li>
        
          <li>
            <a href="/blog/2017/09/10/Linux压缩解压缩命令-index/">Linux常用压缩解压缩命令</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2017 Tayloryu<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/blog/" class="mobile-nav-link">Home</a>
  
    <a href="/blog/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    
<script>
  var disqus_shortname = 'tayloryu';
  
  var disqus_url = 'https://upeng.github.io/blog/2016/08/28/mac-lnmp/';
  
  (function(){
    var dsq = document.createElement('script');
    dsq.type = 'text/javascript';
    dsq.async = true;
    dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
  })();
</script>


<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  <link rel="stylesheet" href="/blog/fancybox/jquery.fancybox.css">
  <script src="/blog/fancybox/jquery.fancybox.pack.js"></script>


<script src="/blog/js/script.js"></script>
  </div>
</body>
</html>